@extends('shop::layouts.master')
@section('title')
    编辑优惠券
@endsection
@section('tab')

		<div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" >
                	{{csrf_field()}}
                    {{hi_form_hidden('id',$info->id)}}
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>优惠券名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="username" name="name" placeholder="请输入优惠券名称" value="{{$info->name}}" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>使用类型</label>
                        <div class="layui-input-inline">
                            <select name="type" required="">
                                <option value="1" @if($info->type == 1 ) selected="selected" @endif >普通商品</option>
                                <option value="2" @if($info->type == 2 ) selected="selected" @endif >服务商品</option>
                                <option value="3" @if($info->type == 3 ) selected="selected" @endif >保养套餐</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="x-red">*</span>优惠券类型</label>
                        <div class="layui-input-inline">
                        <select  name="pid" lay-filter="coupon_type" required="" >
                            <option value="">请选择优惠券类型</option>
                            @foreach( $coupons_types as $key=>$vo )
                                <option value="{{$key}}" @if($info->pid == $key) selected="" @endif >{{$vo}}</option>
                            @endforeach
                        </select>
                        </div>
                    </div>


                    <div class="layui-form-item" id="mj_price"  @if( $info->pid == 1 ||  $info->pid == 3 ) hidden @endif >
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>减(元)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="0.01" name="price" placeholder="请输入优惠金额" value="{{$info->price}}"  autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="zk_price"  @if( $info->pid == 1 ||  $info->pid == 2) hidden @endif>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>折扣数量</label>
                        <div class="layui-input-inline">
                            <input type="number"  id="username" min="1" maxlength="2" placeholder="请输入折扣数量（1~10）" max="10" name="discount_num" value="{{$info->discount_num}}" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="min_price" @if( $info->pid == 1 ) hidden @endif>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>满(元)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" placeholder="请输入最低消费金额" name="price_all" value="{{$info->price_all}}"  autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>优惠券说明</label>
                        <div class="layui-input-inline">
                            <textarea placeholder="请输入优惠券说明" lay-verify="required" name="content" class="layui-textarea" style="width: 400px; height: 100px;">{{$info->content}}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>有效期(天)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" placeholder="领取优惠券后有效期（天）" name="validity_at" value="{{$info->validity_at}}" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>
                    
			        <div class="layui-form-item">
			            <label for="L_repass" class="layui-form-label"></label>
			            <button class="layui-btn" lay-filter="btn_edit" lay-submit="">确认</button>
			        </div>
        		</form>
        	</div>
        </div>


@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(btn_edit)', function (data) {

                $.ajax({
                    url: js_url('shop-coupon-update'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;
            });

            form.on('select(coupon_type)',function(data){
                if( data.value == 1 ){
                    $("#mj_price").hide();
                    $("#zk_price").hide();
                    $("#min_price").hide();
                }else if( data.value == 2 ){
                    $("#mj_price").show();
                    $("#zk_price").hide();
                    $("#min_price").show();
                }else{
                    $("#mj_price").hide();
                    $("#zk_price").show();
                    $("#min_price").show();
                }
            });

        });
    </script>
@endsection